<template>
  <div class="home">
    <el-container>
      <el-header>
        <p class="run">管理平台</p>
        <p><span>欢迎 : admin</span> <el-button @click="Esc">退出</el-button></p>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse?'60px':'200px'">
          <div v-model="isCollapse" @click="isCollapse=!isCollapse" class="isCollapse" >
            |||
          </div>
          <el-menu
            :default-active="$route.path"
            class="el-menu-vertical-demo"
            background-color="#333744"
            text-color="#fff"
            router
            active-text-color="#ffd04b"
            :unique-opened="true"
            :collapse="isCollapse"
            
          >
            <el-submenu
              :index="item.id + ''"
              v-for="item in menu"
              :key="item.id"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item
                  :index="'/'+ele.path"
                  v-for="ele in item.children"
                  :key="ele.id"
                  >{{ ele.authName }} </el-menu-item
                >
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { menus } from "@/http/user.js";
export default {
  data() {
    return {
      menu: [],
      isCollapse: false,
    };
  },
  computed:{
    ...mapGetters(['username'])
  },
  methods: {
    Esc() {
      this.$store.commit('user/DEL_token')
      this.$store.commit('user/DEL_username')
      this.$router.push('/login')
    },

    async menuFn() {
      let res = await menus();
      this.menu = res.data;
      // console.log(res);
      if (res.meta.status == 200) {
        this.$message({
          message: res.meta.msg,
          type: "success",
        });
      } else {
        this.$message.error(res.meta.msg);
      }
    },
  },
  watch:{
    $route(n){
      console.log(n.path);
      localStorage.setItem('RedirectPath',n.path)
    }
  },
  created() {
    this.menuFn();
  },
};
</script>
<style lang="scss" scoped>
.el-header {
  background-color: #333;
  color: white;
  text-align: center;
  line-height: 60px;
  display: flex;
  justify-content: space-between;
  padding: 0 20px;
  .run {
    font-weight: bold;
    font-size: 23px;
  }
}

.el-aside {
  color: #333;
 
  //去除左侧导航栏抖动
  // height: calc(100% - 60px);
}

.el-main {
  background-color: #e9eef3;
  color: #333;
   height: calc(100% - 60px);
}
.isCollapse{
  text-align: center;
  height: 25px;
  line-height: 25px;
  background-color: #4a5064;
  color: white;
}
.el-menu-vertical-demo{
  height: 100vh;
 
}
</style>
